package com.ys.dto;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
 * dtree格式数据
 * @author Jason
 *
 */
@Data
@AllArgsConstructor
public class DtreeSqlDto {
	
	private StatusDto status;
	private List<DataDto> data;

	@Data
	@AllArgsConstructor
	public static class StatusDto {
		private int code;
		private String message;
		
		public static StatusDto init(int code, String message) {
			StatusDto dto = new StatusDto(code, message);
			return dto;
		}
	}
	
	@Data
	@AllArgsConstructor
	public static class DataDto {

		private String id; // 主键ID
		private String title; // 文本
		private String parentId;
		private JSONObject checkArr; // 选中状态配置项，格式有多种，数组：[{"type": "0", "checked": "0"}]，对象：{"type": "0", "checked": "0"}（选中状态，0未选中1已选中2半选），数值：0
		private List<DataDto> children;
		
		public static JSONObject initCheckArr(Integer checked) {
			checked = checked == null ? 0 : checked;
			JSONObject JO = new JSONObject();
			JO.put("type", "0");
			JO.put("checked", checked);
			return JO;
		}
	}
}